/*
 * @Author: jiu yin
 * @Date: 2025-03-05 21:42:20
 * @LastEditTime: 2025-03-05 23:03:54
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \web-mall-admin\scripts\CheckNodeVersion.js
 */

import { versionCompare } from "../src/utils/index.js";
import fs from 'fs'

console.log('\x1b[34m%s\x1b[0m', '正在检查 Node.js 版本...');

const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
const packageJsonNodeVersion = packageJson.engines.node;

const checkNode = () => {
	let nodeVersion = process.version;
	const result = versionCompare(nodeVersion, packageJsonNodeVersion);
	if (result == -1) {
		console.error("\x1b[31m%s\x1b[0m", `当前Node版本${nodeVersion}低于要求Node版本${packageJsonNodeVersion}`);
		process.exit(1);
	}
	console.log("\x1b[32m%s\x1b[0m", `Node版本${nodeVersion}检查通过`);
};

checkNode();
